package controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.BookingDTO;
import model.UserDTO;
import bizlogic.BookingManager;

/**
 * Servlet implementation class RejectBookingServlet
 */
public class RejectBookingServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RejectBookingServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		BookingManager bm = new BookingManager();
		BookingDTO bd;
		SimpleDateFormat df = new SimpleDateFormat();
		
		try
		{
			java.sql.Date ValidateOn =new java.sql.Date(df.parse((df.format(new Date()))).getTime());
			UserDTO ud = (UserDTO)request.getSession(true).getAttribute("user");
			bd = bm.findBooking(request.getParameter("rejectid"));
			bd.setStatus("Rejected");
			bd.setValidateOn(ValidateOn);
			bd.setValidateBy(ud.getName());
			bm.updateBooking(bd);
			
			response.sendRedirect("ViewPendingBooking");
		} catch (ParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
